//
//  CalendarColCell.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/7/26.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "CalendarColCell.h"
#import "ImagePickerManager.h"
@implementation CalendarColCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.backgroundColor = [UIColor clearColor];
    [self.bgView setImage:[[UIImage imageNamed:@"cornerBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"cornerBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"cornerBg"].size.height/2]];
    self.backgroundColor = [UIColor clearColor];
}
-(void)setCellValue:(UserUseListModel*)model{
    self.model = model;
    [self.prdIcon setImage:[UIImage imageNamed:@"icon_default"]];
    self.createTimeLab.text = [NSString stringWithFormat:@"%@",[self timestampSwitchTime:model.addTime/1000 andFormatter:@"yyyy.MM.dd"]];
    self.useTimeLengthLab.text = [NSString stringWithFormat:@"%.0f",model.useTimeLength];
    self.startTimeLab.text = [NSString stringWithFormat:@"%@",[self timestampSwitchTime:model.useTime/1000 andFormatter:@"hh:mm"]];
    self.totalTimeLab.text = @"暂无";
    self.totalCountLab.text  = @"1";
    if (!EC_ISNullStr(model.useFeel)) {
        self.feelLab.text = [NSString stringWithFormat:@"%@",model.useFeel];
    }else{
        self.feelLab.text = @"暂无";
    }
    if (!EC_ISNullStr(model.usePicture)) {
        [self.feelImgBtn setImage:[UIImage new] forState:UIControlStateNormal];
        [self.feelImgBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:model.usePicture] forState:UIControlStateNormal];
    }else{
        [self.feelImgBtn setImage:[UIImage imageNamed:@"xiangji"] forState:UIControlStateNormal];
        [self.feelImgBtn setBackgroundImage:[UIImage new] forState:UIControlStateNormal];
    }
}
#pragma mark - 将某个时间戳转化成 时间
-(NSString *)timestampSwitchTime:(double)timestamp andFormatter:(NSString *)format{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:format]; // （@"YYYY-MM-dd hh:mm:ss"）----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    [formatter setTimeZone:timeZone];
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp];
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    
    return confromTimespStr;
    
}
-(IBAction)uploadImg:(id)sender{
    if ([self.delegate respondsToSelector:@selector(goRecordUploaded:)]) {
        [self.delegate goRecordUploaded:self.model];
    }
}
-(IBAction)uploadText:(id)sender{
    if ([self.delegate respondsToSelector:@selector(goTextUploaded:)]) {
        [self.delegate goTextUploaded:self.model];
    }
}
#pragma mark - instance
-(UploadViewModel*)uploadViewModel{
    if (!_uploadViewModel) {
        _uploadViewModel = [[UploadViewModel alloc]init];
    }
    return _uploadViewModel;
}
@end
